package org.jimmy.tang.lang;

/**
 * @author jimmy
 * 
 */
public class MethodParameters {
    public static void main(String[] args) {
        Employee[] staff = new Employee[2];
        staff[0] = new Employee("Bob", 1000);
        staff[1] = new Employee("Jim", 2000);

        // doesn't work
        swap(staff[0], staff[1]);
        System.out.println(staff[0].getName());// Bob
        System.out.println(staff[1].getName());// Jim

        staff[0].raiseSalary(0.5);// 涨50%的工资
        System.out.println(staff[0].getSalary());// 1500.0

        System.out.println(staff[0].getId());// 1
        System.out.println(staff[1].getId());// 2
    }

    public static void swap(Employee x, Employee y) {
        Employee temp = x;
        x = y;
        y = temp;
    }

}

class Employee {
    public Employee(String name, double salary) {
        this.name = name;
        this.salary = salary;
        id = nextId;
        nextId++;
    }

    public String getName() {
        return name;
    }

    public double getSalary() {
        return salary;
    }

    public int getId() {
        return id;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setSalary(double salary) {
        this.salary = salary;
    }

    public void raiseSalary(double percent) {
        salary *= (1 + percent);
    }

    private String name;
    private double salary;
    private int id;
    private static int nextId = 1;
}
